package com.junit.src;

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.hibernate.beans.Ptnt;


public class HibernateTest {
private SessionFactory sessionFactory;
private Session session = null;

@Before
public void before() {
}

@Test
public void returnsHerosWithMatchingType() {
	 System.out.println("Sarat => Configuring hibernate ... ");
	 Configuration cfg = new Configuration().configure();
	 System.out.println("Sarat => Done hibernate config... ");
	 
	 ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
			 cfg.getProperties()).buildServiceRegistry();

	 System.out.println("Sarat => Building session factory ");
	 sessionFactory = cfg.buildSessionFactory(serviceRegistry);
	 
	 System.out.println("Sarat => Creating Patient...");
	 /*Ptnt ptnt = new Ptnt("Moshai", "A","Doe",(new Date()),28,"Johnny Jumbo","M",
			 "No work","Some detail for the sake of it","hellooooo....",(new Date()),"smarudh",(new Date()),"smarudh");*/
	 
	 System.out.println("Sarat => Opening Session ");
	 session = sessionFactory.openSession();
	 
	 System.out.println("Sarat => Beginning Transaction");
	 Transaction tx = session.beginTransaction();
	 
	 System.out.println("Sarat => Saving to the session");
	 //session.save(ptnt);
	 
	 System.out.println("Sarat => Committing transaction");
	 
	 System.out.println("Sarat => Done... session (before commit) = " + session);
	 
	 tx.commit();
	 
	 System.out.println("Sarat => Done... session (after commit)= " + session);
}

@After
public void after() {
}
}
